package com.slofzx.nuoda.evaluation.project.controller;

import com.slofzx.nuoda.evaluation.project.dto.ProjectYearDataDTO;
import com.slofzx.nuoda.evaluation.project.vo.ProjectYearDataVO;
import com.slofzx.nuoda.evaluation.project.service.ProjectYearDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.slofzx.nuoda.common.controller.BaseController;
import com.slofzx.nuoda.common.vo.AjaxResultVO;
import com.slofzx.nuoda.common.vo.PageResultVO;
import com.slofzx.nuoda.common.enums.ServiceResult;

import java.util.*;

import javax.annotation.Resource;

/**
 * 项目年度数据控制层
 *
 * @author nuoda
 * @menu 项目年度数据
 * @since 2023-10-20 15:57:43
 */
@RestController
@RequestMapping("/project_year_data")
public class ProjectYearDataController extends BaseController {
    /**
     * 服务对象
     */
    @Autowired
    private ProjectYearDataService projectYearDataService;

    /**
     * 通过查询条件查询列表数据
     *
     * @param dto 查询参数
     * @return 列表数据
     */
    @GetMapping("/data")
    public AjaxResultVO<List<ProjectYearDataVO>> queryList(ProjectYearDataDTO dto) {
        List<ProjectYearDataVO> dataList = projectYearDataService.queryList(dto);
        return PageResultVO.newSuccessResult(dataList, dto.getCount());
    }

    /**
     * 通过项目id查询项目系数
     *
     * @param
     * @return map key 系数类型 value
     *         ->map  key 年 value ->系数
     *
     */
    @PostMapping("/queryRatio")
    public AjaxResultVO<Map<String,List<Map<String,String>>>> queryRatioByProjectIds(@RequestBody Set<String> projectIds) {
        Map<String,List<Map<String,String>>> dataList = projectYearDataService.queryRatioByProjectIds(projectIds);
        return AjaxResultVO.newSuccessResult(dataList);
    }

    /**
     * 保存调整系数
     *
     * @param dto 参数数据
     * @return 操作结果
     */
    @ResponseBody
    @PostMapping(value = "/saveRatio")
    public AjaxResultVO saveRatio(@RequestBody List<ProjectYearDataDTO> dto) {
        ServiceResult resultEnum = projectYearDataService.saveRatio(dto);
        return AjaxResultVO.newSuccessResult(resultEnum);
    }

    /**
     * 创建数据
     *
     * @param dto 参数数据
     * @return 操作结果
     */
    @ResponseBody
    @PostMapping(value = "/create")
    public AjaxResultVO create(@RequestBody ProjectYearDataDTO dto) {
        ServiceResult resultEnum = projectYearDataService.create(dto);
        return AjaxResultVO.getInstance(resultEnum);
    }

    /**
     * 数据更新
     *
     * @param dto
     * @return 操作结果
     */
    @ResponseBody
    @PostMapping(value = "/update")
    public AjaxResultVO update(@RequestBody ProjectYearDataDTO dto) {
        ServiceResult resultEnum = projectYearDataService.update(dto);
        return AjaxResultVO.getInstance(resultEnum);
    }

    /**
     * 删除数据
     *
     * @param id
     * @return 操作结果
     */
    @ResponseBody
    @PostMapping(value = "/delete")
    public AjaxResultVO delete(@RequestParam String id) {
        ServiceResult resultEnum = projectYearDataService.deleteById(id);
        return AjaxResultVO.getInstance(resultEnum);
    }

    /**
     * 查询单个数据
     *
     * @return id对应数据
     */
    @ResponseBody
    @GetMapping(value = "/info/{id}")
    public AjaxResultVO<ProjectYearDataVO> queryById(@PathVariable String id) {
        ProjectYearDataVO vo = projectYearDataService.queryById(id);
        return AjaxResultVO.newSuccessResult(vo);
    }

}
